package com.miyake.dsp.osa.lab.ui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import com.miyake.dsp.osa.lab.SettingPanelListener;
import com.miyake.dsp.otdr.OtdrImpulseResponseSetting;
import com.miyake.dsp.otdr.OtdrSetting;
import com.miyake.dsp.otdr.ui.OtdrSettingUI;
import com.miyake.dsp.ui.DspWidget.DspWidgetHandler;

public class OtdrSettingPanelUI extends SettingPanelUI {


	@Override
	protected void createCustomComponent(Object o) {
		JButton otdrButton = new JButton("OTDR Setting");
		add(otdrButton);
		final OtdrSetting otdrSetting = (OtdrSetting)o;
		final OtdrImpulseResponseSetting s = new OtdrImpulseResponseSetting(otdrSetting.getSamplingFrequency(), otdrSetting.getWavelength(), otdrSetting.getDistanceRange());
		final OtdrSettingUI ui = new OtdrSettingUI(s);
		otdrSetting.setEntryPoint(s.getEntryPoint());
		otdrButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				
				JFrame f = new JFrame();
				f.setSize(new Dimension(400, 300));
				f.getContentPane().add(ui);
				f.setVisible(true);
				
				ui.addHandler(new DspWidgetHandler() {

					@Override
					public void onChange(String value) {
						otdrSetting.setEntryPoint(s.getEntryPoint());
						fireOnSet();
					}
					
				});
				
			}
		});
		add(otdrButton);
	}


	/**
	 * 
	 */
	private static final long serialVersionUID = 8345503765545998815L;

	public OtdrSettingPanelUI(Object o) {
		super(o);
	}

	public OtdrSettingPanelUI(final Object o, SettingPanelListener listener) {
		super(o, listener);
	}

}
